using System;
using System.IO;
using System.Text;

namespace PKGames.AssetLoader
{
	public class FileHelper
	{
		public static void DeleteFile(string filePath)
		{
			if (File.Exists(filePath))
			{
				File.Delete(filePath);
			}
		}

		public static void RenameFile(string filePath, string newFilePath)
		{
			DeleteFile(newFilePath);
			File.Move(filePath, newFilePath);
		}

		public static string ReplaceExtension(string path, string newExtension)
		{
			int num = path.LastIndexOf(".");
			if (num > 0)
			{
				return path.Substring(0, num) + newExtension;
			}
			return string.Empty;
		}

		public static string GetFileNameFromURL(string url)
		{
			return Path.GetFileName(new Uri(url).AbsolutePath);
		}

		public static long GetFileSizeInBytes(string filePath)
		{
			FileInfo fileInfo = new FileInfo(filePath);
			return fileInfo.Length;
		}

		public static void CreateDirectory(string folder)
		{
			if (!Directory.Exists(folder))
			{
				Directory.CreateDirectory(folder);
			}
		}

		public static void DeleteDirectory(string directoryPath)
		{
			if (Directory.Exists(directoryPath))
			{
				string[] files = Directory.GetFiles(directoryPath);
				string[] directories = Directory.GetDirectories(directoryPath);
				string[] array = files;
				foreach (string path in array)
				{
					File.SetAttributes(path, FileAttributes.Normal);
					File.Delete(path);
				}
				string[] array2 = directories;
				foreach (string directoryPath2 in array2)
				{
					DeleteDirectory(directoryPath2);
				}
				Directory.Delete(directoryPath, recursive: false);
			}
		}

		public static void DoNotBackupInCloud(string filePath)
		{
		}

		public static string GetFileContent(string filePath)
		{
			StringBuilder stringBuilder = new StringBuilder();
			using (StreamReader streamReader = new StreamReader(filePath))
			{
				string value;
				while ((value = streamReader.ReadLine()) != null)
				{
					stringBuilder.AppendLine(value);
				}
			}
			return stringBuilder.ToString();
		}
	}
}
